#ifndef _DevicesHT1621_H_
#define _DevicesHT1621_H_


#define HT1621_CS1_GPIO_Port    GPIOB
#define HT1621_CS1_Pin          GPIO_PIN_5

#define HT1621_CS2_GPIO_Port    GPIOC
#define HT1621_CS2_Pin          GPIO_PIN_12

#define HT1621_WR_GPIO_Port     GPIOB
#define HT1621_WR_Pin           GPIO_PIN_3

#define HT1621_RD_GPIO_Port     GPIOB
#define HT1621_RD_Pin           GPIO_PIN_4

#define HT1621_DATA_GPIO_Port   GPIOA
#define HT1621_DATA_Pin         GPIO_PIN_15

#define HT1621_VLCD_GPIO_Port   GPIOC
#define HT1621_VLCD_Pin         GPIO_PIN_13


#define HT1621_CS1_HIGH()   gpio_bit_set(HT1621_CS1_GPIO_Port, HT1621_CS1_Pin)
#define HT1621_CS1_LOW()    gpio_bit_reset(HT1621_CS1_GPIO_Port, HT1621_CS1_Pin)

#define HT1621_CS2_HIGH()   gpio_bit_set(HT1621_CS2_GPIO_Port, HT1621_CS2_Pin)
#define HT1621_CS2_LOW()    gpio_bit_reset(HT1621_CS2_GPIO_Port, HT1621_CS2_Pin)

#define HT1621_WR_HIGH()    gpio_bit_set(HT1621_WR_GPIO_Port, HT1621_WR_Pin)
#define HT1621_WR_LOW()     gpio_bit_reset(HT1621_WR_GPIO_Port, HT1621_WR_Pin)

#define HT1621_RD_HIGH()    gpio_bit_set(HT1621_RD_GPIO_Port, HT1621_RD_Pin)
#define HT1621_RD_LOW()     gpio_bit_reset(HT1621_RD_GPIO_Port, HT1621_RD_Pin)

#define HT1621_DATA_HIGH()  gpio_bit_set(HT1621_DATA_GPIO_Port, HT1621_DATA_Pin)
#define HT1621_DATA_LOW()   gpio_bit_reset(HT1621_DATA_GPIO_Port, HT1621_DATA_Pin)
#define HT1621_DATA_READ()  gpio_input_bit_get(HT1621_DATA_GPIO_Port, HT1621_DATA_Pin)

#define HT1621_VLCD_HIGH()  gpio_bit_set(HT1621_VLCD_GPIO_Port, HT1621_VLCD_Pin)
#define HT1621_VLCD_LOW()   gpio_bit_reset(HT1621_VLCD_GPIO_Port, HT1621_VLCD_Pin)


/* 本次通信模式 */
#define HT1621_MODE_READ                0x06
#define HT1621_MODE_WRITE               0x05
#define HT1621_MODE_READ_MODIFY_RITE    0x05
#define HT1621_MODE_COMMAND             0x04

/* 命令 */
#define HT1621_COMMAND_SYS_DISABLE      0x00    /* 关闭系统晶振 */
#define HT1621_COMMAND_SYS_ENABLE       0x01    /* 打开系统晶振 */
#define HT1621_COMMAND_OFF              0x02    /* 关闭LCD偏置电压发生器 */
#define HT1621_COMMAND_ON               0x03    /* 打开LCD偏置电压发生器 */
#define HT1621_COMMAND_WDT_ENABLE       0x07    /* 开启看门狗 */
#define HT1621_COMMAND_RC_256k          0x18    /* 选择片内时钟源 */
#define HT1621_COMMAND_BIAS1_3          0x29    /* 选择4个COM口和1/3bia（即0x28|0x01） */

/* 每个 clock 高低电平保持时间 */
#define HT1621_DELAY_BIT_TIME           1
#define HT1621_DELAY_US                 vDelayUs


void vHT1621Init(void);
void vHT1621WriteCommand(uint16_t usCommand);
void vHT1621WriteByte(uint8_t ucAddr, uint8_t ucByte);
void vHT1621WriteDatas(uint8_t ucAddr, uint8_t *pucDatas, int32_t iLength);


#endif
